
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .lie{
            list-style: none;
            width: 200px;
            position: relative;
            
        }
        .lie>li{
            
            background-color:bisque;
        }
        .lie>li>a{
            display: block;
            width: 200px;
            line-height: 40px;
            font-size: 20px;
            text-align: center;
        }
        .lie>.bg{
            background: orange;
        }
        .lie>li>div{
            position: absolute;
            top: 0;
            left: 200px;
            width: 300px;
            height: 200px;
            background: orange;
            display: none;
        }
        .lie>li>.show{
            display: block;
        }
    </style>
</head>
<body>
    <ul class="lie" >
        <li><a href="javascript:;"> 商品1</a>
            <div>商品对应的菜单1</div>
        </li>
        <li><a href="javascript:;"> 商品2</a>
            <div>商品对应的菜单2</div>
        </li>
        <li><a href="javascript:;"> 商品3</a>
            <div>商品对应的菜单3</div>
        </li>
        <li><a href="javascript:;"> 商品4</a>
        </li>
        <li><a href="javascript:;"> 商品5</a>
            <div>商品对应的菜单5</div>
        </li>
    </ul>
    <script>
        // 先获取所有的项
        let lis=document.querySelectorAll('.lie>li')
       lis.forEach(function(open,i){
            open.addEventListener('mouseover',function(){
                open.classList.add('bg')
                // console.log(open.children);
                if(open.children.length==2){
                    open.lastChild.previousSibling.classList.add('show')
                }
            })
            open.addEventListener('mouseout',function(){
                open.classList.remove('bg')
                if(open.children.length==2){
                    open.lastChild.previousSibling.classList.remove('show')
                }
            })
       })

    </script>
</body>
</html>